package com.xlf.service.ai.service;

import com.xlf.common.auth.util.SecurityUtils;
import com.xlf.service.ai.pojo.dto.AiRequest;
import com.xlf.service.ai.pojo.dto.ChatBaseRequest;
import com.xlf.service.ai.pojo.dto.ChatResponse;
import com.xlf.service.ai.service.impl.ErnieBot4Client;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * @Author xlf 2734029211@qq.com
 * @Date 2024/1/27 22:31
 * @Description: TODO
 * @Version 1.0
 */
@Service
public class AiService {

    @Autowired
    ErnieBot4Client ernieBot4Client;


    public String doAnswer(AiRequest aiRequest){

        Long userId = (Long) SecurityUtils.getUserId();
        String userKey =  userId.toString() + ':' + aiRequest.getChatId();
        ChatBaseRequest chatBaseRequest = new ChatBaseRequest();
        chatBaseRequest.setUserId(userId.toString());
        chatBaseRequest.setContent(aiRequest.getContent());
        ChatResponse chatResponse = ernieBot4Client.chatCont(chatBaseRequest, userKey);
        return chatResponse.getResult();
    }



}
